<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\ConfigSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '网站配置列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="config-index">
    <p>
        <?= Html::a('创建网站配置', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <style>
        th,tr{text-align: center}
    </style>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'header' => "操作",
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update} {delete}',
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', '查看'),
                            'class' => 'btn btn-xs btn-info',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                    },
                    'update' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', '编辑'),
                            'class' => 'btn btn-xs btn-info',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
                    },
                    'delete' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', '删除'),
                            'class' => 'btn btn-xs btn-info',
                            'data-confirm' => 'Are you sure you want to delete this item?',
                            'data-method' => 'POST',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
                    },

                ],
            ],

            [
                'attribute' => 'id',
                'value' => 'id',
                'headerOptions' => ['width' => '50'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'cid',
                'value' => function($model) {
                    if($model->cid == 1){
                        return '<span class="btn btn-xs btn-primary">基本设置</span>';
                    }elseif($model->cid == 2){
                        return '<span class="btn btn-xs btn-primary">seo</span>';
                    }else{
                        return '';
                    }
                },
                'filter' => ['1' => '基本设置', '2' => 'seo'],
                'headerOptions' => ['width' => '100'],
            ],
            [
                'format' => 'raw',
                'attribute' => 'type',
                'value' => function($model) {
                    if($model->type == 'img'){
                        return '<span class="btn btn-xs btn-primary">图片</span>';
                    }else{
                        return '<span class="btn btn-xs btn-primary">文本</span>';
                    }
                },
                'filter' => ['text' => '文本', 'img' => '图片'],
                'headerOptions' => ['width' => '100'],
            ],
            'key',
            'title',
            'value',
            //'remark',
            //'sort',
            //'create_time:datetime',
            [
                'format' => 'raw',
                'attribute' => 'create_time',
                'value' => function($model) {
                    return date('Y-m-d H:i:s',$model->create_time);
                },
                'headerOptions' => ['width' => '120'],
            ],
            //'update_time:datetime',
        ],
    ]); ?>


</div>
